import 'package:eleapp/controller/usercontroller.dart';
import 'package:eleapp/res/strings.dart';
import 'package:eleapp/util/save/sp_util.dart';

import 'package:eleapp/widget/myicon.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class Settings extends StatefulWidget {
  const Settings({super.key});

  @override
  State<Settings> createState() => _SettingsState();
}

class _SettingsState extends State<Settings> {
  SystemController systemController = Get.find<SystemController>();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    print('setting组件销毁回调');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blue,
        title: Text(StringStyles.setting.tr),
      ),
      body: ListView(
        padding: const EdgeInsets.only(top: 10),
        children: [
          SizedBox(
              height: 54,
              child: InkWell(
                onTap: () {
                  Get.toNamed('/langsetting');
                },
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      // color: Colors.red,
                      // width: 150,
                      margin: const EdgeInsets.only(left: 20),
                      child: Text(
                        StringStyles.languageSetting.tr,
                        style: const TextStyle(fontSize: 16),
                      ),
                    ),
                    SizedBox(
                      width: 240,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            SpUtil.getLanguage() == null
                                ? StringStyles.followerSystemLanguage.tr
                                : SpUtil.getLanguage()!.name,
                            style: const TextStyle(
                                fontSize: 16,
                                leadingDistribution:
                                    TextLeadingDistribution.even),
                            strutStyle: const StrutStyle(
                              leading: 0,
                              height: 1,
                              // 1.1更居中
                              forceStrutHeight: true, // 关键属性 强制改为文字高度
                            ),
                          ),
                          const SizedBox(
                            width: 5,
                          ),
                          const Icon(Icons.language),
                          const SizedBox(
                            width: 10,
                          )
                        ],
                      ),
                    )
                  ],
                ),
              )),
          const Divider(),
          SizedBox(
            height: 54,
            child: InkWell(
              onTap: () {
                Get.toNamed('/themesetting');
              },
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    // color: Colors.red,
                    // width: 150,
                    margin: const EdgeInsets.only(left: 20),
                    child: Text(
                      StringStyles.themeSetting.tr,
                      style: const TextStyle(fontSize: 16),
                    ),
                  ),
                  SizedBox(
                    width: 240,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Obx(() => Text(
                              systemController.themeName.value,
                              style: const TextStyle(
                                  fontSize: 16,
                                  leadingDistribution:
                                      TextLeadingDistribution.even),
                              strutStyle: const StrutStyle(
                                leading: 0,
                                height: 1,
                                // 1.1更居中
                                forceStrutHeight: true, // 关键属性 强制改为文字高度
                              ),
                            )),
                        const SizedBox(
                          width: 5,
                        ),
                        const Icon(MyIcon.fankong),
                        const SizedBox(
                          width: 10,
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
          const Divider(),
        ],
      ),
    );
  }
}
